#!/bin/bash -ex
set -eu -o pipefail

git clone --depth 1 https://github.com/longld/peda.git

mkdir bin
cat > bin/gdb-peda <<EOF
#!/bin/sh
exec gdb -q -ex init-peda "\$@"
EOF
chmod +rx bin/gdb-peda

cd peda
# make sure gdbinit exists
touch ~/.gdbinit
if ! grep "init-peda" ~/.gdbinit; then
    cat >> ~/.gdbinit <<EOF

####
# added by ctf-tools
define init-peda
    source $PWD/peda.py
end
document init-peda
    Initializes the PEDA (Python Exploit Development Assistant for GDB) framework
end
####

EOF
fi
